package com.vast.ui.component.models;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.ListenerList;

public class LedPanel {
	/*
	 * LedPanel is singleton.
	 */
	private static LedPanel ledPanel = new LedPanel();
	private final  List<Led> ledList;
	private final  ListenerList listenerList;

	private LedPanel() {
		this.ledList      = new ArrayList<Led>();
		this.listenerList = new ListenerList();
	}
	
	public static LedPanel getInstance(){
		return ledPanel;
	}
	
	public List<Led> getList(){
		return ledList;
	}
	
	public void add(Led led){
		ledList.add(led);
		Object[] listeners = listenerList.getListeners();
		for (Object listener : listeners) {
			((LedListener) listener).add(led);
		}
	}
	
	public void remove(Led led){
		ledList.remove(led);
		Object[] listeners = listenerList.getListeners();
		for (Object listener : listeners) {
			((LedListener) listener).remove(led);
		}
	}
	
	public void addListener(LedListener listener){
		listenerList.add(listener);
	}
	
	public void removeListener(LedListener listener){
		listenerList.remove(listener);
	}
	
	public void changeTarget(int index, Led led) {
		ledList.set(index,led);
	}
}
